home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / hpgl2ps.zip / VIEWPORT.C < prev   
C/C++ Source or Header  |  1989-08-08  |  2KB  |  72 lines

  1. /* viewport.c */
  2. /*
  3.  * This procedure sets up the variables for the translation of plotter
  4.  * coordinates to PostScript coordinates.
  5.  *
  6.  * Note: the procedure "defaults" may be incorporated here, however
  7.  *    I have not had the time to work it out properly.
  8.  *
  9.  * Don McCormick
  10.  */
  11. #include "defn.h"
  12. /*  original psxmax */
  13. #define XWIDTH 0.90
  14.  
  15. viewport()
  16. {
  17.     /* original values for A4 */
  18.     /* float pagewidth = 197.0;         Page width for Laser Printer  */
  19.     /* float pageheight = 280.0;     Page height for Laser Printer */
  20.     /* float pwoffset = 12; */
  21.     /* float phoffset = 12; */
  22.  
  23.     /*  8.5 x 11 inch paper */
  24.     float pagewidth = 200.0;        /* Page width for Laser Printer */
  25.     float pageheight = 265.0;        /* Page height for Laser Printer */
  26.     float pwoffset = 28;
  27.     float phoffset = 6;
  28.     /* values above selected empirically to match HP7550A plot -G.J. */
  29.  
  30.     /* made global */
  31.     /* float psxmax, psymax;        Sizes scaled to the viewport */
  32.  
  33.     if (LANDSCAPE)        /* Default mode */
  34.     {
  35.     psymax = pagewidth * XWIDTH;
  36.     psxmax = psymax * (xmax - xmin)/ (ymax - ymin);
  37.     xoffset += (pageheight + phoffset - psxmax) / 2.0;
  38.     yoffset -= (pagewidth + pwoffset + psymax) / 2.0;
  39.     printf("90 rotate\n"); 
  40.     } else
  41.     {
  42.     psxmax = pagewidth * XWIDTH;
  43.     psymax = psxmax * (ymax - ymin) / (xmax - xmin);
  44.     xoffset += (pagewidth + pwoffset - psxmax) / 2.0;
  45.     yoffset += (pageheight + phoffset - psymax) / 2.0;
  46.     }
  47.     printf("%g mm %g mm translate\n", xoffset, yoffset);
  48.     XSCALE = psxmax / (xmax - xmin) * SCALE;
  49.     YSCALE = psymax / (ymax - ymin) * SCALE;
  50.     /* fprintf(stderr,"Xscale = %g  Yscale = %g\n",XSCALE,YSCALE); */
  51. }
  52.  
  53. /* function called when the HP-GL Scale command is received */
  54. /* Modifies the X,Y SCALE factors and the origin offsets */
  55. /*  Added by Gordon Jacobs */
  56.  
  57. modify_viewport()
  58. {
  59.     /* re-calculate scale parameters */
  60.     XSCALE = psxmax / (xmax - xmin) * SCALE;
  61.     YSCALE = psymax / (ymax - ymin) * SCALE;
  62.  
  63.     /* calculate new offset */
  64.     offX = -xmin * XSCALE;
  65.     offY = -ymin * YSCALE;
  66.  
  67.     /*** debug
  68.     fprintf(stderr,"MODIFY: Xscale = %g  Yscale = %g\n",XSCALE,YSCALE);
  69.     fprintf(stderr,"OFFSET: offX = %g  offY = %g\n",offX,offY);
  70.     **********/
  71. }
  72.